<template>
    <div>
        <div class="control">
            <!-- 车牌号 -->
            <div class="inputItem">
                <div class="title">司机姓名</div>
                <div class="inputBox">
                    <el-input v-model="driverName"></el-input>
                </div>
            </div>
            <div class="inputItem">
                <div class="title">创建时间</div>
                <el-date-picker size="small" v-model="createTime" type="datetimerange" :picker-options="pickerOptions"
                    range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" align="right"
                    value-format="yyyy-MM-dd HH:mm:ss">
                </el-date-picker>
            </div>

            <!-- 查询 -->
            <el-button type="primary" size="small" icon="el-icon-search" @click="getList1()">查询</el-button>
            <el-button type="plain" size="small" icon="el-icon-refresh-right" @click="clearUp()">清空</el-button>
        </div>
        <div class="main">
            <div class="list" ref="getHeight">
                <el-table :data="records" style="width: 100%" ref="table2">
                    <el-table-column align="center" width="60px" prop="SerialNumber" label="序号">
                    </el-table-column>
                    <el-table-column prop="driverPhoto" align="center" label="司机照片">
                        <template slot-scope="scope">
                            <el-image style="width: 65px; height: 48px" :src="scope.row.driverPhoto"
                                :preview-src-list="[scope.row.driverPhoto]">
                            </el-image>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="driverName" label="姓名">
                    </el-table-column>
                    <el-table-column align="center" prop="phoneNumber" label="手机号">
                    </el-table-column>
                    <el-table-column align="center" label="准驾车型">
                        <template slot-scope="scope">
                            <span v-if="scope.row.licenseLevel != null">{{
                                scope.row.licenseLevel.message
                            }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="region" label="所属地区">
                    </el-table-column>
                    <el-table-column align="center" prop="numberplate" label="绑定车辆">
                    </el-table-column>
                    <el-table-column align="center" prop="vehicleType" label="车型">
                    </el-table-column>
                    <el-table-column align="center" prop="certStatus.value" label="认证状态">
                        <template>
                            <div class="stateBtns">
                                <el-button class="noPass" size="small">
                                    <i class="iconfont icon-dian"></i>
                                    不通过
                                </el-button>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="createTime" label="创建时间"></el-table-column>
                    <el-table-column align="center" label="操作">
                        <template slot-scope="scope">
                            <div>
                                <!-- @click="$router.push('/certAudit/details/'+id)" -->
                                <el-button type="text" size="small" v-if="permissions.detail2.perms != null" @click="
                                    $router.push('certAudit/details/' + scope.row.driverId)
                                    ">详情</el-button>
                                <el-button type="text" size="small" @click="showAuditDialog(scope.row.driverId)"
                                    v-if="scope.row.certStatus.value == 1 & permissions.edit.perms != null">认证</el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <!-- 分页 -->
            <div class="paginationBox">
                <el-pagination @current-change="changePages($event)" class="pagination" background
                    layout="slot,prev, pager, next" :total="data.total * 1" :page-size="data.size * 1" :pager-count="5">
                    <template slot>
                        <span style="
                  color: #686868;
                  font-size: 12px;
                  margin-right: 20px;
                  display: inline-block;
                ">共{{ data.total }}条,每页{{ data.size }}条</span>
                    </template>
                </el-pagination>
            </div>
        </div>
        <!-- 认证弹窗 -->
        <el-dialog class="dialog" title="司机认证" :visible.sync="visibleDialogBox" width="420px">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="ruleForm">
                <el-form-item label="认证结果" prop="status">
                    <el-radio-group v-model="ruleForm.status">
                        <el-radio :label="'2'">是</el-radio>
                        <el-radio :label="'3'">否</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="认证说明" prop="cerInfo" v-if="ruleForm.status == 3">
                    <el-input type="textarea" resize="none" :rows="3" placeholder="请输入内容"
                        v-model="ruleForm.cerInfo"></el-input>
                </el-form-item>
            </el-form>
            <div style="display: flex; justify-content: flex-end">
                <el-button class="cancelBtn" @click="visibleDialogBox = false">取 消</el-button>
                <el-button class="submitBtn" type="primary" @click="SubmitAudit(ruleForm.status)">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
  
<script>
import breadcrumb from "@/components/breadcrumb.vue";
import httpApi from "@/http";

export default {
    data() {
        return {
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            createTime: "",//创建时间
            driverName: "", //司机姓名
            TypeSelected: "",
            stateSelected: "",
            visibleDialogBox: false,
            records: [],
            data: {},
            pageCurrent: 1, //当前页码
            size: "10",
            ruleForm: {
                status: "",
                cerInfo: "",
            },
            rules: {
                status: [{ required: true, message: "请选择", trigger: "change" }],
                cerInfo: [
                    { max: 200, message: "最大长度200 个字符", trigger: "blur" },
                    { required: true, message: "不能为空", trigger: "blur" },
                ],
            },
            driverId: "",
            permissions: {}
        };
    },
    created() {
        this.permissions = JSON.parse(sessionStorage.getItem('permissions'))
        this.getList();
    },
    methods: {
        getSerialNumber() {
            // 前端解决序号
            this.records.forEach((item, i) => {
                let num = i + 1 + Number(this.size) * (this.pageCurrent - 1);
                item.SerialNumber = num;
            });
        },
		getList1(){
			this.pageCurrent = 1;
			this.getList();
		},
        getList() {
            let params = {
                pageCount: 10,
                pageNo: this.pageCurrent,
                driverName: this.driverName,
                certStatus: "3",
                startTime: this.createTime != null ? this.createTime[0] : '', //开始时间
                endTime: this.createTime != null ? this.createTime[1] : '', //结束时间
            };
            httpApi.driverApi.getWaitAuditDriverList(params).then((res) => {
                this.records = res.data.data.records;
                this.data = res.data.data;
                this.getSerialNumber();
                // console.log(res.data.data);
                // console.log('待认证列表数据', res.data.data.records);
            });
        },

        clearUp() {
            this.driverName = "";
			this.pageCurrent = 1;
            this.createTime = []
            this.getList()
        },
        changePages(val) {
            this.pageCurrent = val;
            this.getList();
        },
        // 显示司机认证弹窗,存储对应的司机ID
        showAuditDialog(driverId) {
            this.visibleDialogBox = true;
            this.driverId = driverId;
        },

        // 司机弹窗 点击确定触发
        SubmitAudit(params) {
            // 2表示通过  3不通过
            this.showMessageBox = true;
            if (params == "2") {
                let params = { status: "2", driverId: this.driverId };
                // console.log('params', params);
                httpApi.driverApi.ModifyDriverCertification(params).then((res) => {
                    // console.log('通过结果', res);
                    // console.log('响应状态码', res.data.code);
                    if (res.data.code == 200) {
                        this.getList();
                        this.$message({
                            type: "success",
                            message: `认证通过!`,
                        });
                    }
                });
            } else if (params == "3") {
                let params = {
                    status: "3",
                    cerInfo: this.ruleForm.cerInfo,
                    driverId: this.driverId,
                };
                // console.log('params', params);
                httpApi.driverApi.ModifyDriverCertification(params).then((res) => {
                    // console.log('不通过结果', res);

                    if (res.data.code == 200) {
                        this.getList();
                        this.$message({
                            type: "error",
                            message: `认证驳回!`,
                        });
                    }
                });
            }
            this.visibleDialogBox = false;
        },
        // 记录滚动距离
        scrollEvent(res) {
            this.$route.meta.scrollTop = res.target.scrollTop
        },
    },
    activated() {
        //组件激活时监听表格滚动条位置,
        this.$refs.table2.bodyWrapper.addEventListener('scroll', this.scrollEvent, false)
        // 激活设置滚动位置
        this.$refs.table2.bodyWrapper.scrollTop = this.$route.meta.scrollTop
    },
    beforeRouteLeave(to, from, next) {
        // 为了节省资源，再离开页面的时候关闭对于scroll事件的监听
        this.$refs.table2.bodyWrapper.removeEventListener('scroll', this.scrollEvent)
        next()
    },

    mounted() {
    },
};
</script>
  
<style lang="scss" scoped>
.control {
    height: 76px;
    width: 100%;
    background-color: #fff;
    display: flex;
    align-items: center;
    padding: 0 29px;

    .inputItem {
        display: flex;
        align-items: center;
        margin-right: 23px;

        >.title {
            color: #262626;
            font-size: 12px;
            margin-right: 7px;
        }

        >.inputBox {
            width: 160px;

            ::v-deep .el-input__inner {
                height: 32px;
                font-size: 12px;
            }

            ::v-deep .el-input__inner::placeholder {
                color: #c3c3c3;
                font-size: 12px;
            }
        }
    }
}

.main {
    width: 100%;
    height: calc(100vh - 267px);
    background-color: #fff;

    .list {
        height: calc(100% - 48px);
        padding: 0 30px;

        ::v-deep .el-table__body-wrapper {
            height: calc(100vh - 362px);
            overflow-y: scroll;
        }

        // 表头样式
        ::v-deep .el-table__header th {
            background-color: #f0f6fd;
            color: #262626;
            font-size: 12px;
            font-weight: bold;
            text-align: center;

            // 表 body的td
            ::v-deep .el-table__body td {
                color: #595959;
                font-size: 12px;
            }
        }

        .stateBtns {
            height: 30px;
            width: 76px;
            margin: 0 auto;

            ::v-deep .el-button {
                height: 30px;
                width: 76px;
                font-size: 12px;
                border: none;
                display: flex;
                align-items: center;
                justify-content: center;
                line-height: 30px;
            }

            .waitPass {
                background-color: #ecf5fe;
                color: #1890ff;
            }

            .noPass {
                background-color: #fde8e9;
                color: #f7555d;
            }
        }
    }

    .paginationBox {
        border-top: 1px solid #f0f0f0;
        width: 100%;
        background-color: #fff;
        display: flex;
        height: 48px;
        align-items: center;
        padding: 0 30px;

        .pagination {
            margin-left: auto;
        }
    }
}
</style>
  